package org.mspring.mlog.service;

import java.util.List;

import org.mspring.mlog.dao.LinkTypeDao;
import org.mspring.mlog.entity.LinkType;
import org.mspring.platform.dao.Page;
import org.mspring.platform.dao.query.QueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Gao Youbo
 * @since 2013-06-18 16:34:42
 */
@Service
@Transactional
public class LinkTypeService {

    @Autowired
    private LinkTypeDao linkTypeDao;

    public List<LinkType> listVisables() {
        return linkTypeDao.listVisables();
    }

    public LinkType get(long id) {
        return linkTypeDao.get(id);
    }

    public Page<LinkType> listPage(QueryBuilder queryBuilder, Page<LinkType> page) {
        return linkTypeDao.listPage(queryBuilder, page);
    }

    public void update(LinkType linkType) {
        linkTypeDao.update(linkType);
    }

    public void delete(Long... ids) {
        linkTypeDao.delete(ids);
    }

    public Long insert(LinkType linkType) {
        linkType.setVisable(true);
        return linkTypeDao.insert(linkType);
    }

    public void updateLinkTypeName(Long[] ids, String[] names) {
        if (ids == null || names == null || ids.length == 0 || ids.length != names.length) {
            return;
        }
        for (int i = 0; i < ids.length; i++) {
            long id = ids[i];
            String name = names[i];
            linkTypeDao.updateLinkTypeName(id, name);
        }
    }

    public void updateLinkTypeOrder(Long[] ids, Long[] orders) {
        if (ids == null || orders == null || ids.length == 0 || ids.length != orders.length) {
            return;
        }
        for (int i = 0; i < ids.length; i++) {
            long id = ids[i];
            long order = orders[i];
            linkTypeDao.updateLinkTypeSort(id, order);
        }
    }

    public void updateLinkTypeVisable(boolean visable, Long... ids) {
        if (ids == null || ids.length == 0) {
            return;
        }
        for (Long id : ids) {
            linkTypeDao.updateLinkTypeVisable(id, visable);
        }
    }

}
